<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        body {
            padding: 0;
            margin: 0;
            height: 100vh;
            min-width: 300px;
            display: flex;
        }

        .main {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;

            .btn {
                margin: 5px 0px;
                width: 50vw;
                border-radius: 99999999px;
                border: none;
                background-color: #5091fa;
                color: #fff;
                padding: 10px 0;
                cursor: pointer;


                &&:hover {
                    opacity: 0.8;
                }
            }
        }
    </style>
</head>

<body>

    <div class="main">
        <button class="btn">抖音自动取消关注</button>
        <button class="btn" onclick="getChat('模拟输出')">获取流输出</button>
        <div class="chatText"></div>

    </div>
</body>


<script>

    // 抖音自动取消关注
    function dyNotFollow() {
        let btn = document.querySelectorAll('.Pxf0E4cv .vcEWxPjN .GNgMFcUD .bJi_3A3L')
        let index = 0;

        const interval = setInterval(() => {
            if (index >= btn.length) {
                clearInterval(interval);  // 如果所有按钮都被点击过，则停止定时器
                console.log('取消关注 结束了');
                return;
            }

            btn[index].click();  // 点击当前索引的按钮
            index++;
        }, 1000);
    }


    // 模拟ChatGPT输出
    async function getChat(content) {
        let chatText = document.querySelector(".chatText")
        chatText.innerHTML = ''

        const post = await fetch("http://192.168.31.45:3000/nlp/chat", {
            method: 'post',
            headers: {
                'accept': 'text/event-stream',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ content })
        })
        const reader = post.body.getReader()
        const decoder = new TextDecoder()

        while (1) {
            let { done, value } = await reader.read()
            if (done) break;
            chatText.innerHTML += decoder.decode(value)
        }

    }

</script>

</html>